// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';
import 'package:junyeyishu/widgets/QGListState.dart';

class QGSynthesisRecordPage extends StatefulWidget {
  String id;
  QGSynthesisRecordPage({super.key, required this.id});
  @override
  State<QGSynthesisRecordPage> createState() => _QGSynthesisRecordPageState();
}

class _QGSynthesisRecordPageState extends QGListState<QGSynthesisRecordPage> {
  @override
  void initState() {
    super.initState();

    listURL = url_user_getMyCombinelog;
    listKey = "list";

    onRefresh();
  }

  @override
  Map listParam() {
    return {"id": widget.id};
  }

  @override
  Widget build(BuildContext context) {
    return QGScaffold(
        title: '合成记录',
        bgColor: Color(0xFFF8F8F6),
        body: Column(children: [SizedBox(height: 10.rpx), buildList()]));
  }

  @override
  Widget itemBuilder(context, index, dynamic itemData) {
    return Stack(
      children: [
        Container(
          margin: EdgeInsets.only(bottom: 10.rpx, left: 10.rpx, right: 10.rpx),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6.rpx),
            color: Color(0xFFFFFFFF),
          ),
          padding: EdgeInsets.all(15.rpx),
          child: Row(
            children: [
              ClipRRect(
                borderRadius: BorderRadius.circular(4.rpx),
                child: QGImage(
                    url: itemData?["thumb_img"], width: 80.rpx, height: 80.rpx),
              ),
              SizedBox(width: 15.rpx),
              Column(
                children: buildItems(itemData["conditions"] ?? []),
              ),
            ],
          ),
        ),
      ],
    );
  }

  buildItems(conditions) {
    List<Widget> children = [];

    for (var item in conditions) {
      var child = Container(
        margin: EdgeInsets.only(bottom: 5.rpx, top: 5.rpx),
        child: Text(
          '${item["goods_name"]}：${item["goods_num"]}',
          style: TextStyle(
              color: Color(0xFF111111),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        ),
      );
      children.add(child);
    }
    return children;
  }
}
